/**
 * ThirdPartyResponseStringXmlParser.java
 * author: yujiakui
 * 2017年8月29日
 * 上午10:16:52
 */
package com.ctim.service.integration.parser.impl;

import java.io.Reader;
import java.io.StringReader;
import java.util.List;

import org.springframework.stereotype.Component;

import com.ctim.common.exception.PcsRunTimeException;
import com.ctim.service.enums.ParserTypeEnum;
import com.google.common.collect.Lists;

/**
 * @author yujiakui
 *
 *         上午10:16:52
 *
 *         输入对象是String的xml解析器
 */
@Component("thirdPartyResponseStringXmlParser")
public class ThirdPartyResponseStringXmlParser extends AbstractThirdPartyResponseXmlParser {

	/*
	 * (non-Javadoc)
	 *
	 * @see com.ctim.service.integration.parser.impl.
	 * AbstractThirdPartyResponseXmlParser#getInputObjReader(java.lang.Object)
	 */
	@Override
	protected Reader getInputObjReader(Object inputObj) {
		check(inputObj);// 校验输入对象
		String inputStrObj = (String) inputObj;
		return new StringReader(inputStrObj);
	}

	/**
	 * 校验输入对象
	 *
	 * @param inputObj
	 */
	private void check(Object inputObj) {
		if (!(inputObj instanceof String)) {
			throw new PcsRunTimeException(
					"解析器ThirdPartyResponseStringXmlParser对应的inputObj的类型不是String");
		}
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.ctim.service.integration.parser.ThirdPartyResponseParser#
	 * getParseTypes()
	 */
	@Override
	public List<ParserTypeEnum> getParseTypes() {
		return Lists.newArrayList(ParserTypeEnum.STRING_XML);
	}

}
